package model

import "github.com/gin-gonic/gin"

type SecondGrade struct {
	ENo                string `gorm:"column:e_no"`
	SProfessionalGrade string `gorm:"column:s_professional_grade"`
	InterviewGrade     string `gorm:"column:interview_grade"`
	PracticeGrade      string `gorm:"column:practice_grade"`
	Count              string `gorm:"column:count"`
}

func InsertSecondGrade(c *gin.Context) (error, SecondGrade) {
	var secondgradedate SecondGrade
	c.BindJSON(&secondgradedate)
	err := DB.Table("secondgrades").Select("e_no", "s_professional_grade", "interview_grade", "practice_grade", "total_num").Create(&secondgradedate).Error
	return err, secondgradedate
}

func GetSecondGrade(resparam map[string]interface{}) (error, []SecondGrade, int64) {
	var secondgradedate []SecondGrade
	page := resparam["page"].(int)
	pageSize := resparam["limit"].(int)
	searchText := resparam["searchText"].(string)
	var total int64
	err := DB.Table("secondgrades").Where("e_no like ? ", "%"+searchText+"%").Count(&total).Offset((page - 1) * pageSize).Limit(pageSize).Find(&secondgradedate).Error
	return err, secondgradedate, total
}
